﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Janus.Windows.GridEX;
using OrderAggregator.DataStorage;

namespace OrderAggregator.UI
{
    public partial class EditDialog : Form
    {
        
        public EditDialog()
        {
            InitializeComponent();

            Icon = UIManager.GetIcon("App.ico");
        }
        
        /// <summary>
        /// Get or set hosted control
        /// </summary>
        public Control HostedControl
        {
            get
            {
                if (panel2.Controls.Count == 0)
                {
                    return null;
                }

                return panel2.Controls[0];
            }
            set
            {
                panel2.Controls.Clear();
                
                if (value != null)
                {
                    var hostSize = panel2.Size;
                    hostSize.Width -= value.Width;
                    hostSize.Height -= value.Height;

                    value.Dock = DockStyle.Fill;
                    panel2.Controls.Add(value);

                    this.Width -= hostSize.Width;
                    this.Height -= hostSize.Height;
                }
            }
        }
        

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (HostedControl is BaseEditListControl)
            {
                (HostedControl as BaseEditListControl).SaveChanges();
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
